﻿using CMWVS.Core.Commands;
using CMWVS.Core.Projects;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace bleissem.CMWVS
{
    public class BuildCompileParameters
    {
        public static void Build(EnvDTE.Solution solution, TraceListener listener, out CompileCommandParamater parameter)
        {
            if ((null == solution) || (string.IsNullOrWhiteSpace(solution.FullName)))
            {
                parameter = new CompileCommandParamater();
                return;
            }

            EnvDTE.SolutionConfiguration activeConfiguration = solution.SolutionBuild.ActiveConfiguration;
            EnvDTE80.SolutionConfiguration2 activeSolutionConfiguration2 = (EnvDTE80.SolutionConfiguration2)activeConfiguration;

            string buildConfiguration = activeConfiguration.Name;
            string platform = activeSolutionConfiguration2.PlatformName;

            CompileCommandParamater result = new CompileCommandParamater(new Solution(new FileInfo(solution.FullName)), buildConfiguration, platform, listener);

            parameter = result;
        }

        public static void Build(EnvDTE.Solution solution, TraceListener listener, out RebuildCommandParameters parameter)
        {
            if ((null == solution) || (string.IsNullOrWhiteSpace(solution.FullName)))
            {
                parameter = new RebuildCommandParameters();
                return;
            }

            EnvDTE.SolutionConfiguration activeConfiguration = solution.SolutionBuild.ActiveConfiguration;
            EnvDTE80.SolutionConfiguration2 activeSolutionConfiguration2 = (EnvDTE80.SolutionConfiguration2)activeConfiguration;

            string buildConfiguration = activeConfiguration.Name;
            string platform = activeSolutionConfiguration2.PlatformName;

            RebuildCommandParameters result = new RebuildCommandParameters(new Solution(new FileInfo(solution.FullName)), buildConfiguration, platform, listener);

            parameter = result;
        }

        public static void Build(EnvDTE.Solution solution, TraceListener listener, out CleanCommandParameters parameter)
        {
            if ((null == solution) || (string.IsNullOrWhiteSpace(solution.FullName)))
            {
                parameter = new CleanCommandParameters();
                return;
            }

            EnvDTE.SolutionConfiguration activeConfiguration = solution.SolutionBuild.ActiveConfiguration;
            EnvDTE80.SolutionConfiguration2 activeSolutionConfiguration2 = (EnvDTE80.SolutionConfiguration2)activeConfiguration;

            string buildConfiguration = activeConfiguration.Name;
            string platform = activeSolutionConfiguration2.PlatformName;

            CleanCommandParameters result = new CleanCommandParameters(new Solution(new FileInfo(solution.FullName)), buildConfiguration, platform, listener);

            parameter = result;
        }
    }
}